const app = getApp()

import {
  payReFundRequest
} from '../../api/user'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderNum: "",
    goodsNum: "",
    goodsPrice: "",
    makeTime: "",
    useTime: "",
    goodsName: "",
    // goodsInfo: "",
    orderId: ''
  },

  onLoad: function (options) {

    console.log('退款数据')
    console.log(options)
    this.setData({
      orderNum: options.orderNum,
      goodsNum: options.goodsNum,
      goodsPrice: options.goodsPrice,
      makeTime: options.makeTime,
      useTime: options.useTime,
      goodsName: options.goodsName,        // 商品名称
      orderId: options.orderId
    });

    // var goodsData = JSON.parse(options.item);
    // console.log('退款数据')
    // console.log(goodsData)
    // this.setData({
    //   goodsInfo: goodsData,
    // })

    wx.setNavigationBarTitle({
      title: '退款详情',
    })

    // this.getData();
  },

  refundAction: function () {
    console.log("tuikuan")
    let that = this
    tt.showModal({
      title: '是否确认退款',
      content: '提交退款后,将会有一到三个工作日审核期,且不可撤回',
      cancelColor: '#444444',
      confirmColor: '#ff4200',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          that.reFundActionRequest()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  // /** 数据绑定 */
  // getData: function () {
  //   this.setData({
  //     orderNum: this.data.goodsInfo.orderId,
  //     goodsNum: this.data.goodsInfo.num,
  //     goodsPrice: this.data.goodsInfo.totalPrice,
  //     makeTime: this.data.goodsInfo.createTime,
  //     useTime: this.data.goodsInfo.invalidTime,
  //     goodsName: this.data.goodsInfo.name,          // 商品名称
  //   });
  // },

  reFundActionRequest: function () {

    tt.showLoading({
      title: '请稍后', // 内容
    });

    let params = {
      orderId: this.data.orderId,
    };
    console.log(params)
    payReFundRequest(params).then((res) => {
      console.log('payReFundRequest请求成功')
      tt.hideLoading();
        tt.showModal({
          title: '退款申请成功',
          content: '退款申请成功,一个工作日到账',
          showCancel: false,//是否显示取消按钮
          confirmText:"确认",//默认是“确定”
          confirmColor: 'linear-gradient(90deg, #FF7D7D 0%, #F34747 100%)',//确定文字的颜色
          success: function (res) {
            tt.navigateBack();
          },
          fail: function (res) { },//接口调用失败的回调函数
          complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
       })
      // tt.navigateBack();
    }).catch((res) => {
      console.log('payReFundRequest请求失败')
      console.log(res)
      tt.showToast({
        title: res.data.msg,
        icon: 'none',
        duration: 2000
      })
    })
  }



})
